package com.yunji.hushuang.plugin.demo.interceptor;

import com.yunji.hushuang.plugin.Interceptor;
import com.yunji.hushuang.plugin.Intercepts;
import com.yunji.hushuang.plugin.Invocation;
import com.yunji.hushuang.plugin.Signature;
import com.yunji.hushuang.plugin.demo.source.DemoParam;
import com.yunji.hushuang.plugin.demo.source.IExecutor;

/**
 * 时间拦截器，统计方法调用时间
 *
 * @author hushuang
 * @since 2019/10/16
 */
@Intercepts(@Signature(type = IExecutor.class, method = "execute", args = DemoParam.class))
public class TimeInterceptor implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Exception {
        long start = System.currentTimeMillis();
        Object result = invocation.proceed();
        long end = System.currentTimeMillis();
        System.out.println("TimeInterceptor 总共耗时：" + (end - start));
        return result;
    }
}